﻿<!DOCTYPE html>

<html>
<head>
    <link href="@(Logic.Constants.CurrentUrl)/Content/Box.css" rel="stylesheet" type="text/css" />
    <link href="@(Logic.Constants.CurrentUrl)/Content/Login.css" rel="stylesheet" type="text/css" />
    <link href="@(Logic.Constants.CurrentUrl)/Content/General.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="OuterBox">
    <div class="Title">Login</div>
    <div class="Body">
        @using (Html.BeginForm())
        {
            <div class="LoginForm">
                @Html.AntiForgeryToken()
                <div class="Left">
                    <div class="Label">User Name</div>
                    <div>@Html.TextBox("tbUserName", (String)ViewBag.UserName)</div>
                    <div class="Label">Password</div>
                    <div>@Html.Password("tbPassword")</div>
                    <div class="Error">@ViewBag.ErrorMesage</div>
                    <div class="LoginButton"><input type="submit" value="Login" class="Button"/> </div>
                    <div class="Links">
                        <span class='Link' onclick='openOauthBrowsers()'>Automatic Login</span>
                        |
                        <span class='Link' onclick='window.open("https://app.clarizen.com/Clarizen/Pages/Service/ForgotPassword.aspx")'>Can’t access your account?</span>
                    </div>
                </div>
                <div class="Right">
                    <h1>Not registered yet?</h1>
                    <div><input type="button"  value="30 days free trial >>" onclick='window.open("https://app.clarizen.com/Clarizen/Pages/Service/Registration.aspx")' class="GreenButton"/></div>
                    <div class="Indent">Go Beyond Project Management and discover what Real-Time Execution will do for your business.</div>
                   
                </div>
            </div>
        }
    </div>
</div>

 <script type="text/javascript"  language="javascript"  src="https://api.conduit.com/BrowserCompApi.js"></script>
 <script src="@(Logic.Constants.CurrentUrl)/Scripts/jquery-1.4.4.min.js" type="text/javascript"></script>
 <script>
     var goto = '@ViewBag.Goto';


     @if (ViewBag.ResetToken != null && ViewBag.ResetToken)
     {
        <text>
             window.onload = function ()
             {
                try
                {
                 if (typeof GetInfo != "undefined" && GetInfo())
                     StoreGlobalKey("accessToken", "");
                else
                    Set_Cookie("access_token", "", true, '/', false, true);
                }
                catch (er)

                {
                Set_Cookie("access_token", "", true, '/', false, true);
                }
             }
         </text>
     }
     
//    var tokenSet = false;

//    var win;
//    var int;
    
    function openOauthBrowsers()
    {
//        if($.browser.webkit)
//            openOauthChrome();
//        else 
            openOauth();
    }

    function openOauth()
    {
        try
        {
        SelfNavigate("@(Logic.Constants.CurrentUrl)/Oauth/Oauth?goto=" + escape(goto));    

        }
        catch (er)
        {
        window.location.href = "@(Logic.Constants.CurrentUrl)/Oauth/Oauth?goto=" + escape(goto);   
        }
    }
    

    function openOauthChrome()
    {
        window.open("/Oauth/Oauth", "Oauth" + Math.round(Math.random() * 1000000), "width:500px,height:300px");
    }

    function Set_Cookie( name, value, expires, path, domain, secure )
    {
    // set time, it's in milliseconds
    var today = new Date();
    today.setTime( today.getTime() );

    /*
    if the expires variable is set, make the correct
    expires time, the current script below will set
    it for x number of days, to make it for hours,
    delete * 24, for minutes, delete * 60 * 24
    */
    if ( expires )
    {
    expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date( today.getTime() + (expires) );

    document.cookie = name + "=" +escape( value ) +
    ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
    ( ( path ) ? ";path=" + path : "" ) +
    ( ( domain ) ? ";domain=" + domain : "" ) +
    ( ( secure ) ? ";secure" : "" );
    }

    function setAccessToken(token)
    {
        try
        {
        if (typeof GetInfo != "undefined" && GetInfo())
            StoreGlobalKey("accessToken", token);
        else
            Set_Cookie("access_token", token, true, '/', false, true);
        }
        catch (er)
        {
        Set_Cookie("access_token", token, true, '/', false, true);
        }
        goToNext();
    }

    function goToNext()
    {
        if (goto && goto.length > 4)
            window.location = goto;
        else window.location = '/tasks/index';
    }
 </script>

 </body>
</html>
